//
// Created by Administrator on 2023/11/15.
//
#include "iostream"

using namespace std;

const int N = 7;
int path[N];
bool visited[N];
int n;

//x是计数器
void dfs(int x) {

    if(x==n){
        for (int i = 0; i <n; ++i)
            cout<<path[i]<<" ";
        cout<<endl;
    }

    for (int i = 1; i <= n; ++i) {
       if(!visited[i]) {
           path[x]=i;
           visited[i]= true;
           dfs(x+1);
           visited[i]= false;
       }

    }
}

int main() {
    cin >> n;
    dfs(0);
}